3 Building Web Maps in R Studio

tmap_mode("view")
## tmap mode set to interactive viewing
usa_trifecta_map
## legend.postion is used for plot mode. Use view.legend.position in tm_view to set the legend position in view mode.
tmap_mode("plot")
## tmap mode set to plotting
usa_trifecta_map

Make a webmap that shifts Alaska and Hawaii back to their actual locations:

usa_unshifted<-st_read("usa_unshifted.shp")
## Reading layer `usa_unshifted' from data source `/Users/adra7980/Documents/git_repositories/gistools_qda/data/usa_unshifted.shp' using driver `ESRI Shapefile'
## Simple feature collection with 52 features and 3 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -179.1473 ymin: 17.88481 xmax: 179.7785 ymax: 71.35256
## geographic CRS: NAD83
usa_unshifted
## Simple feature collection with 52 features and 3 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -179.1473 ymin: 17.88481 xmax: 179.7785 ymax: 71.35256
## geographic CRS: NAD83
## First 10 features:
##    GEOID           NAME abbrev                       geometry
## 1     23          Maine     ME MULTIPOLYGON (((-67.61976 4...
## 2     25  Massachusetts     MA MULTIPOLYGON (((-70.83204 4...
## 3     26       Michigan     MI MULTIPOLYGON (((-88.68443 4...
## 4     30        Montana     MT MULTIPOLYGON (((-104.0577 4...
## 5     32         Nevada     NV MULTIPOLYGON (((-114.0506 3...
## 6     34     New Jersey     NJ MULTIPOLYGON (((-75.52684 3...
## 7     36       New York     NY MULTIPOLYGON (((-71.94356 4...
## 8     37 North Carolina     NC MULTIPOLYGON (((-82.60288 3...
## 9     39           Ohio     OH MULTIPOLYGON (((-82.81349 4...
## 10    42   Pennsylvania     PA MULTIPOLYGON (((-75.41504 3...
# join tabular data to "usa_unshifted"
usa_unshifted_trifecta<-inner_join(usa_unshifted, usa_trifecta_data, by="abbrev")

# sets factor
usa_unshifted_trifecta<-usa_unshifted_trifecta %>% 
                          mutate(Composition=factor(Composition, levels=c("Democratic Trifecta", 
                                                  "Republican Trifecta", "Divided Government"))) %>% 
                          rename(State=NAME.x) %>% 
                          relocate(State, Composition)



# recreate map
usa_trifecta_map_unshifed<-tm_shape(usa_unshifted_trifecta)+
                                tm_polygons(col="Composition", 
                                            palette=colors,
                                            title="")+
                                tm_layout(frame=FALSE,
                                          main.title="Partisan Composition of State Governments, 2022",
                                          main.title.size=1,
                                          main.title.position="center")

# change to view mode
tmap_mode("view")
## tmap mode set to interactive viewing
usa_trifecta_map_unshifed
## tmap mode set to plotting